package com.pesilo.module.home.mvc.view
{
	import com.pesilo.module.home.mvc.controller.ApplicationFacade;
	import com.pesilo.module.home.mvc.view.component.HomeComponent;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class ApplicationMediator extends Mediator implements IMediator
	{
		public static const NAME:String="ApplicationMediator";
		public function ApplicationMediator(viewComponent:Object)
		{
			super(NAME,viewComponent);
		}
		
		
		override public function listNotificationInterests():Array{
			return [
				ApplicationFacade.EVENT_SHOW,
				ApplicationFacade.EVENT_HIDE
			];
		}
		
		override public function handleNotification(notification:INotification):void{
			var data:Object=notification.getBody();
			switch(notification.getName()){
				case ApplicationFacade.EVENT_SHOW:
					if(!view.homeCmp){
						view.homeCmp=new HomeComponent();
					}
					view.addChild(view.homeCmp);
					break;
				case ApplicationFacade.EVENT_HIDE:
					if(view.contains(view.homeCmp)){
						view.removeChild(view.homeCmp);
					}
					break;
			}
		}
		
		protected function get view():App{
			return viewComponent as App;
		}
	}
}